package com.caoustc.okhttplib.okhttp

import android.text.TextUtils

class Part {
    var key: String? = null
        protected set(key) {
            field = key ?: ""
        }
    var value: String? = null
        set(value) {
            field = value ?: ""
        }
    var fileWrapper: FileWrapper? = null
        private set

    constructor(key: String?, value: String?) {
        this.key = key
        this.value = value
    }

    constructor(key: String?, fileWrapper: FileWrapper?) {
        this.key = key
        this.fileWrapper = fileWrapper
    }

    /**
     * 修改为判断key是否相同来判断是否相同
     * @param o
     * @return
     */
    override fun equals(o: Any?): Boolean {
        if (o == null || o !is Part) {
            return false
        }
        return TextUtils.equals(o.key, key)
    }

    override fun hashCode(): Int {
        var result = key?.hashCode() ?: 0
        result = 31 * result + (value?.hashCode() ?: 0)
        result = 31 * result + (fileWrapper?.hashCode() ?: 0)
        return result
    }
}